package Week5.J0518;

import java.util.Scanner;

public class 爱吃素 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while (n-- != 0) {
            long a = scanner.nextLong(), b = scanner.nextLong();
            if ((a == 1 && isPrime(b)|| (b == 1 && isPrime(a)))) {
                System.out.println("YES");
            }else {
                System.out.println("NO");
            }
        }
    }

    private static boolean isPrime(long b) {
        if (b < 2) return false;
        for (int i = 2; i <= Math.sqrt(b); i++) {
            if (b % i == 0) return false;
        }
        return true;
    }
}
